package com.huaxin.hxmoduleworkorder.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.huaxin.hxmoduleworkorder.common.enums.MaintenanceOrderElectricianTaskOperation;
import com.huaxin.hxmoduleworkorder.common.enums.MaintenanceOrderElectricianTaskStatus;
import com.huaxin.hxmoduleworkorder.common.enums.MaintenanceOrderOperatorRole;
import com.huaxin.hxmoduleworkorder.common.enums.MaintenanceOrderStatus;
import com.huaxin.hxmoduleworkorder.dto.ResponseResult;
import com.huaxin.hxmoduleworkorder.dto.request.*;
import com.huaxin.hxmoduleworkorder.dto.response.MaintenanceOrderElectricianTaskDetailRespDto;
import com.huaxin.hxmoduleworkorder.dto.response.MaintenanceOrderElectricianTaskSummaryRespDto;
import com.huaxin.hxmoduleworkorder.models.MaintenanceOrder;
import com.huaxin.hxmoduleworkorder.models.MaintenanceOrderElectricianTask;

import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

public interface MaintenanceOrderElectricianTaskService extends IService<MaintenanceOrderElectricianTask> {
    /* *********************************************************************
     * 工单任务基础 CRUD 操作
     ********************************************************************* */

    void createTasks(List<MaintenanceOrderElectricianTaskCreateReqDTO> in);

    void updateTasks(MaintenanceOrderElectricianTaskUpdateReqDTO in);

    MaintenanceOrderElectricianTask get(String id);

    void deleteByOrderId(String orderId);

    /* *********************************************************************
     * 电工任务状态与流程管理
     ********************************************************************* */

    ResponseResult<String> getTaskStatus(String taskId);

    List<MaintenanceOrderElectricianTaskOperation> getAvailableOperations(String taskId, MaintenanceOrderOperatorRole operatorRole);

    Boolean canOperate(String taskId, MaintenanceOrderElectricianTaskOperation operation, MaintenanceOrderOperatorRole operatorRole);

    void updateStatus(MaintenanceOrderElectricianTaskUpdateStatusReqDto in, Consumer<MaintenanceOrderElectricianTask> additionalUpdater);

    void updateStatusByOrderId(String orderId, MaintenanceOrderElectricianTaskStatus status, MaintenanceOrderElectricianTaskOperation action, String remarks);

    ResponseResult<String> accept(MaintenanceOrderElectricianTaskAcceptReqDto in);

    ResponseResult<String> onSite(MaintenanceOrderElectricianTaskOnSiteReqDto in);

    ResponseResult<String> startProcess(MaintenanceOrderElectricianTaskProcessingReqDto in);

    ResponseResult<String> submitResult(MaintenanceOrderElectricianTaskSubmitResultReqDto in);

    ResponseResult<String> resolve(MaintenanceOrderElectricianTaskResolveReqDto in);

    ResponseResult<String> reject(MaintenanceOrderElectricianTaskRejectReqDto in);

    MaintenanceOrderStatus calculateOrderStatus(MaintenanceOrder order);

    /* *********************************************************************
     * 分页与条件查询
     ********************************************************************* */

    List<MaintenanceOrderElectricianTask> listByOrderId(String orderId);

    Boolean existsResolvedTask(String orderId);

    Boolean isAssigned(String orderId, String electricianId);

    ResponseResult<Page<MaintenanceOrderElectricianTaskSummaryRespDto>> pageQuery(MaintenanceOrderElectricianTaskPageListReqDTO in);

    List<MaintenanceOrderElectricianTaskSummaryRespDto> getIncompleteTasks(String electricianId);

    MaintenanceOrderElectricianTaskDetailRespDto detail(String taskId);

    /* *********************************************************************
     * 统计与报表
     ********************************************************************* */

    Map<String, Long> incompleteTaskCountByElectrician();
}